package com.fin.zw.intelligentbot.util;

import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.net.URI;

public class SocketClient {
    static Session session;

    public static void socketSend(String url,String json){
        try {
            WebSocketContainer container = ContainerProvider.getWebSocketContainer();
            System.out.println("Connecting to " + url);
            container.connectToServer(MsgWebSocketClient.class, URI.create(url));
            session.getBasicRemote().sendText(json);
            java.io.BufferedReader r=new  java.io.BufferedReader(new java.io.InputStreamReader( System.in));
            while(true){
                String line=r.readLine();
                if(line== null ||line.equals("quit")) break;
                session.getBasicRemote().sendText(line);
            }
        } catch ( Exception ex) {
            ex.printStackTrace();
        }
    }
}
